<template>
    <div class="home">
      <home-header></home-header>
      <home-nav :navIndex="navIndex"></home-nav>
      <el-carousel class="carousel" height="320px" arrow="always" :autoplay="attris.autoplay" :interval="attris.interval">
        <el-carousel-item v-for="(item,index) in bannerList" :key="index">
          <el-image :src="item.src" :title="item.alt" :alt="item.alt" fit="fit" ></el-image>
        </el-carousel-item>
      </el-carousel>
      <div class="container">
        <div class="soon">
          <span class="s-l">即将上映 <i class="icon icon-right"></i></span>
          <span class="s-c"><img class="icon-img" src="@/images/icon-virus.png" alt="">黄石公园第三季</span>
          <span class="s-r"><img class="icon-img" src="@/images/icon-virus.png" alt="">行尸走肉：超越世界第一季</span>
        </div>
        <div class="recom">
          <div class="top">
            <div class="title">好剧推荐</div>
          </div>
          <div class="section">
            <div class="intager" @click="checkDetail(med)">
              <el-image :src="med.src" ></el-image>
              <div class="intrduce">
                <i class="icon-top"></i>
                <div>{{med.introduce}}</div>
              </div>
            </div>
            <div class="list">
              <div class="citem" v-for="(citem,cindex) in comList" :key="cindex" @click="checkDetail(citem)">
                <el-image :src="citem.src" :title="citem.title" lazy></el-image>
                <div class="desc">
                  <div class="title">{{citem.title}}</div>
                  <div class="status">状态：{{citem.status}}</div>
                </div>
                <div v-if="citem.src" class="play" :title="citem.title"></div>
              </div>
            </div>
          </div>
        </div>
        <div class="rank">
          <div class="top">
            <div class="title">好剧排行榜</div>
          </div>
          <div class="rank-storm">
            <el-row :gutter="10">
              <el-col :xs="24" :sm="12" :md="6" :lg="6" :xl="6" v-for="(ritem,rindex) in rankList" :key="rindex">
                <div class="title">{{ritem.title}}</div>
                <div class="">
                  <div class="header ritem" >
                    <div class="ranking">排名</div>
                    <div class="name">剧名</div>
                    <div class="date">日期</div>
                  </div>
                  <div class="content ritem" v-for="(item,index) in ritem.list" :key="index" @click="checkDetail(item)">
                    <div class="ranking"><em class="index" :class="{'triple':index<=2}">{{index + 1}}</em></div>
                    <div class="name" :title="item.title">{{item.title}}</div>
                    <div class="date">{{item.date}}</div>
                  </div>
                </div>
              </el-col>
            </el-row>
          </div>
        </div>
        <div class="links">
          <div class="f-lk">友情链接</div>
          <div class="guise"><span>美剧网</span><span>美剧下载</span><span>电影资源</span></div>
        </div>
      </div>
      <bottom></bottom>
    </div>
</template>

<script>
import HomeHeader from '@/components/HomeHeader.vue'
import HomeNav from '@/components/HomeNav'
import Bottom from '@/components/Bottom'
import {getMovieList} from '@/api/movieList'
import {getBannerList} from '@/api/banner'
export default {
  name: 'index',
  components: {
    HomeHeader,
    HomeNav,
    Bottom
  },
  metaInfo: {
    title: '九月电影网',
    meta: [
      {name: 'keywords', content: '九月电影网'}
    ]
  },
  data () {
    return {
      navIndex: 0,
      bannerList: [],
      imgLoading: true,
      attris: {
        autoplay: true,
        interval: 5000
      },
      med: {},
      comList: [],
      rankList: [],
      loading: true,
      fullscreenLoading: true
    }
  },
  created () {
    this.fetchData()
    this.fetchBanner()
  },
  methods: {
    checkDetail (item) {
      let routeUrl = this.$router.resolve({
        path: '/detail',
        query: {id: item.source_id}
      })
      window.open(routeUrl.href, '_blank')
      // this.$router.push({path:'/detail',query:{id:item.source_id}})
    },
    fetchData () {
      getMovieList().then(response => {
        let data = response.data
        this.med = data.med
        this.comList = data.tuijian
        this.rankList.push({'title': '今日更新', 'list': data.today})
        this.rankList.push({'title': '昨日更新', 'list': data.yestoday})
        this.rankList.push({'title': '新剧上映', 'list': data.new})
        this.rankList.push({'title': '本周排行', 'list': data.week})
        this.fullscreenLoading = false
      })
    },
    fetchBanner () {
      getBannerList().then(response => {
        let data = response.data
        this.bannerList = data.list
      })
    }
  }
}
</script>

<style lang="scss" scoped>
.home {
  .carousel {
    background: #282828;
    margin: auto;
    text-align: center;
  }
  >>> .el-carousel__container {
    width: 980px;
    margin: auto;
  }
  .el-carousel__arrow.el-carousel__arrow--left {
  }
  .el-image {
    cursor: pointer;
  }
  .container {
    width: 980px;
    margin: auto;
    .soon {
      margin: 5px 0;
      line-height: 40px;
      color: #666;
      font-weight: bold;
      border: 1px solid #F0F0F0;
      display: flex;
      align-items: center;
      .s-l {
        padding: 0 20px;
        color: #484848;
        font-size: 14px;
        font-weight: bold;
        border-right: 1px solid #DEDEDE;
        background: #F6F7F6;
        position: relative;
        .icon-right {
          width: 12px;
          height: 12px;
          background: #F6F7F6;
          border-top: 1px solid #DEDEDE;
          border-right: 1px solid #DEDEDE;
          box-sizing: border-box;
          transform: rotateZ(45deg);
          position: absolute;
          top: 35%;
          right: -7px;
        }
      }
      .s-c, .s-r {
        cursor: pointer;
        &:hover {
          color: #25AB00;
        }
      }
      .icon-img {
        margin-left: 30px;
        margin-right: 5px;
        width: 18px;
        height: 18px;
        vertical-align: text-bottom;
      }
    }
    .top {
      border-bottom: 1px solid #ECECEC;
      display: flex;
      justify-content: space-between;
      align-items: center;
      .title {
        font-size: 16px;
        font-weight: bold;
      }
      .more {
        color: #929292;
      }
    }
    .recom{
      .top {
        .title{
          padding-right: 40px;
          line-height: 38px;
          border-bottom: 2px solid #00C064;
        }
      }
      .section {
        padding-top: 10px;
        display: flex;
        justify-content: space-between;
        .intager {
          width: 230px;
          .intrduce {
            margin-top: 15px;
            padding: 10px;
            color: #929292;
            background: #efefef;
            position: relative;
            .icon-top{
              width: 14px;
              height: 14px;
              background: #efefef;
              transform: rotate(-45deg);
              position: absolute;
              top: -7px;
              left: 20px;
            }
          }
        }
        .list {
          flex: 1;
          display: flex;
          flex-wrap: wrap;
        }
        .citem {
          margin-left: 15px;
          width: 130px;
          position: relative;
          &:hover{
            .title{
              color: #00C064;
            }
            .play {
              opacity: .3;
            }
          }
          .el-image {
            height: 173px;
          }
          .desc {
            padding-bottom: 10px;
            font-size: 12px;
          }
          .title {
            color: #373737;
          }
          .status {
            color: #929292;
          }
          .play {
            background: #000 url('../images/play.png') no-repeat center;
            opacity: 0;
            cursor: pointer;
            position: absolute;
            top: 0;
            left: 0;
            right: 0;
            bottom: 45px;
            z-index: 2;
          }
        }
      }
    }
    .rank{
      .top {
        .title {
          line-height: 38px;
          border-bottom: 2px solid #07A7E3;
        }
      }
      .rank-storm {
        padding: 5px 5px 15px;
        border: 1px solid #f2f2f2;
        .title {
          padding: 0 10px;
          line-height: 36px;
        }
      }
      .ritem {
        padding-left: 15px;
        line-height: 30px;
        border-bottom: 1px dashed #EDEDED;
        display: flex;
        justify-content: space-between;
        align-items: center;
        &.header{
          line-height: 26px;
          color: #464646;
          background: #f3f3f3;
        }
        .ranking {
          min-width: 45px;
          .index {
            display: inline-block;
            width: 15px;
            height: 15px;
            line-height: 15px;
            color: #fff;
            text-align: center;
            background: #BDC3BF;
          }
          .triple {
            background: #FF912F;
          }
        }
        .name {
          flex: 1;
          overflow: hidden;
          text-overflow: ellipsis;
          display: -webkit-box;
          -webkit-line-clamp: 1;
          -webkit-box-orient: vertical;
        }
        .date {
          min-width: 55px;
          color: #8C8D92;
        }
      }
      .content {
        .name {
          color: #7E7E7E;
          cursor: pointer;
        }
      }
    }
  }
  .links {
    margin: 10px 0 20px;
    padding: 10px;
    border: 1px solid #ECECEC;
    .f-lk {
      padding: 0 5px;
      font-size: 16px;
      font-weight: bold;
      border-left: 3px solid #00C064;
    }
    .guise {
      padding: 10px;
      color: #929292;
      font-size: 12px;
      & > span {
        margin-right: 15px;
        cursor: pointer;
        &:hover{
          color: #00C064;
        }
      }
    }
  }
}
</style>
